package com.gitee.wsl.android.ui.recyclerView.itemDecoration.builder

import android.content.Context
import android.content.res.Resources
import android.util.TypedValue
import androidx.annotation.DimenRes

/**
 * @Author : HHotHeart
 * @Time : 2021/5/31 15:38
 * @Description : StaggeredGridLayoutManager分割线构造器（不支持draw颜色设置）
 */
class XStaggeredGridBuilder(context: Context) : XDividerDecoration.Builder(
    context
) {
    /**
     * 分割线宽或高,mVLineSpacing||mHLineSpacing > mSpacing
     */
    var vLineSpacing = 0
        private set
    var hLineSpacing = 0
        private set
    var spacing = 0
        private set

    /**
     * 是否需要画边界
     */
    var isIncludeEdge = false
        private set

    /**
     * 是否忽略fullSpan的情况
     */
    var isIgnoreFullSpan = false
        private set

    /**
     * 设置分割线间距
     *
     * @param dpValueSpacing
     * @return
     */
    fun setSpacing(dpValueSpacing: Float): XStaggeredGridBuilder {
        spacing = DividerHelper.applyDimension(dpValueSpacing, TypedValue.COMPLEX_UNIT_DIP).toInt()
        return this
    }

    /**
     * 设置分割线间距
     *
     * @param dimenResId
     * @return
     */
    fun setSpacing(@DimenRes dimenResId: Int): XStaggeredGridBuilder {
        spacing = Resources.getSystem().getDimensionPixelSize(dimenResId)
        return this
    }

    /**
     * 设置竖直线间距
     *
     * @param dpValueVLineSpacing
     * @return
     */
    fun setVLineSpacing(dpValueVLineSpacing: Float): XStaggeredGridBuilder {
        vLineSpacing =
            DividerHelper.applyDimension(dpValueVLineSpacing, TypedValue.COMPLEX_UNIT_DIP).toInt()
        return this
    }

    fun setVLineSpacing(@DimenRes dimenResId: Int): XStaggeredGridBuilder {
        vLineSpacing = Resources.getSystem().getDimensionPixelSize(dimenResId)
        return this
    }

    /**
     * 设置水平线间距
     *
     * @param dpValueHLineSpacing
     * @return
     */
    fun setHLineSpacing(dpValueHLineSpacing: Float): XStaggeredGridBuilder {
        hLineSpacing =
            DividerHelper.applyDimension(dpValueHLineSpacing, TypedValue.COMPLEX_UNIT_DIP).toInt()
        return this
    }

    fun setHLineSpacing(@DimenRes dimenResId: Int): XStaggeredGridBuilder {
        hLineSpacing = Resources.getSystem().getDimensionPixelSize(dimenResId)
        return this
    }

    /**
     * 设置是否包含边界
     *
     * @param includeEdge
     * @return
     */
    fun setIncludeEdge(includeEdge: Boolean): XStaggeredGridBuilder {
        isIncludeEdge = includeEdge
        return this
    }

    /**
     * 设置是否忽略fullSpan的情况
     *
     * @param ignoreFullSpan
     * @return
     */
    fun setIgnoreFullSpan(ignoreFullSpan: Boolean): XStaggeredGridBuilder {
        isIgnoreFullSpan = ignoreFullSpan
        return this
    }
}